/**
 * Created by wxb on 2016/10/21.
 */
(function () {
  'use strict';

  angular.module('BlurAdmin.theme.components')
    .controller('PageTopCtrl', PageTopCtrl);

  /** @ngInject */
  function PageTopCtrl($scope, loginService, localStorageService, $state, toastr, $window, $uibModal, hotelManageService, md5) {
    $scope.user = localStorageService.cookie.get('user');
    console.log($scope.user);

    $scope.logout = function () {
      localStorageService.cookie.set('user', {anonymous: true});
      toastr.success('注销成功', '成功!');
      $state.go('login', {}, {reload: true});
      $window.location.reload();
    };

    $scope.changePassword = function () {
      var modalInstance = $uibModal.open({
        animation: true,
        templateUrl: 'app/pages/support/modal/setPassword.html',
        controller: 'SetPasswordModalCtrl',
        resolve: {
        }
      });

      modalInstance.result.then(function (modalItem) {
        var postData = {};
        postData.password = md5.createHash(modalItem.password);
        postData.newPassword = md5.createHash(modalItem.newPassword);
        hotelManageService.changePassword(postData).then(function (data) {
          if (data && data.errcode === 0) {
            toastr.success('密码修改成功', '成功!');
          }
        })

      });
    }


  }

})();
